package com.xxxx.yoyo.adminweb;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xxxx.yoyo.bean.User;
import com.xxxx.yoyo.service.IUserService;
import com.xxxx.yoyo.service.impl.UserServiceImpl;

/**
 * 删除客户账号
 * Servlet implementation class UserDeleteServlet
 */
@WebServlet("/admin/userDelete")
public class UserDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private IUserService userService = new UserServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置导航条上的[客户管理]处于选中状态
		request.setAttribute("flag",2);
		
		//获取前端传递过来的参数id
		String userIdstr = request.getParameter("id");
		int userId = Integer.parseInt (userIdstr);
		
		//根据用户id获取用户信息
		User user = userService.getUserById(userId);
		//把用户的状态改为0
		user.setStatus(0);//status为1表示用户正常，为0表示用户被删除了
		//更新数据库用户信息
		boolean isSuccess = userService.updateUser(user);
		if(isSuccess){//更新成功
			//重定向到客户管理列表页面
			response.sendRedirect ("/YoyoShop/admin/userList?page=1&size=16");
		}
	}

}
